package com.xiaoyezi.demo2.base;

import java.io.Serializable;

// import com.xiaoyezi.demo2.DataSource.User;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor

public class BaseEntity<T>implements Serializable{
    private T data;              // 数据源
    private boolean success;     // 请求状态
    private int code;            // 响应码   
    private String error;        // 错误提示

    // 请求成功
    public static <T> BaseEntity<T> success(T t){
        BaseEntity<T> base = new BaseEntity<>();
        base.setCode(200);
        base.setData(t);
        base.setSuccess(true);
        return base;
    }
    // 请求失败
    public static <T> BaseEntity<T> failed(int code,String error){
        BaseEntity<T> base = new BaseEntity<>();
        base.setCode(code);
        base.setData(null);
        base.setSuccess(false);
        base.setError(error);
        return base;
    }
    // 重载
    public static <T> BaseEntity<T> failed(String error){
        return failed(606,error);
    }
}
